package com.bw.house.controller;

import com.bw.house.service.TbHouseInfoService;
import com.bw.result.ResultVo;
import com.bw.vo.AssignVo;
import com.bw.vo.IdVo;
import com.bw.vo.LoginVo;
import com.bw.vo.TbHouseInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

/**
 * @author liuzhihao
 * @version 1.0
 * @description: TODO
 * @date 2023/11/10 21:02:36
 */
@RestController
@Slf4j
@RequestMapping("/house")
@Api(tags = "房源管理")
public class TbHouseInfoController {

    @Autowired
    private TbHouseInfoService tbHouseInfoService;

    /** @Author 曹承坤
     * @Description //TODO 新增房源
     * @Date 09:02 23/11/11
     * @Param
     * @param tbHouseInfoVo
     * @return
     * @return com.bw.result.ResultVo
     **/
    @PostMapping("/insertHouse")
    @ApiOperation("新增房源")
    public ResultVo add(@RequestBody TbHouseInfoVo tbHouseInfoVo, @RequestHeader String token){
        return tbHouseInfoService.add(tbHouseInfoVo,token);
    }

    /** @Author 曹承坤
     * @Description //TODO 修改房源
     * @Date 09:02 23/11/11
     * @Param
     * @param tbHouseInfoVo
     * @return
     * @return com.bw.result.ResultVo
     **/
    @PostMapping("/updateHouse")
    @ApiOperation("修改房源")
    @CacheEvict(cacheNames = "com.bw.vo.TbHouseInfoVo",key = "#tbHouseInfoVo.id")
    public ResultVo update(@RequestBody TbHouseInfoVo tbHouseInfoVo){
        return tbHouseInfoService.update(tbHouseInfoVo);
    }

    /** @Author 曹承坤
     * @Description //TODO 删除房源
     * @Date 09:02 23/11/11
     * @Param
     * @param tbHouseInfoVo
     * @return
     * @return com.bw.result.ResultVo
     **/
    @PostMapping("/deleteHouse")
    @ApiOperation("删除房源")
    @CacheEvict(cacheNames = "com.bw.vo.TbHouseInfoVo",key = "#tbHouseInfoVo.id")
    public ResultVo deleted(@RequestBody TbHouseInfoVo tbHouseInfoVo){
        return tbHouseInfoService.deleted(tbHouseInfoVo);
    }

    /** @Author 曹承坤
     * @Description //TODO 房源列表
     * @Date 09:02 23/11/11
     * @Param
     * @param tbHouseInfoVo
     * @return
     * @return com.bw.result.ResultVo
     **/
    @PostMapping("/houseList")
    @ApiOperation("房源列表")
    public ResultVo houseList(@RequestBody TbHouseInfoVo tbHouseInfoVo){
        return tbHouseInfoService.houseList(tbHouseInfoVo);
    }

   /** @Author 曹承坤
     * @Description //TODO 给房源指派经纪人
     * @Date 09:02 23/11/11
     * @Param
     * @param assignVo
     * @return
     * @return com.bw.result.ResultVo
     **/
    @PostMapping("/assign")
    @ApiOperation("指派经纪人")
    public ResultVo assign(@RequestBody AssignVo assignVo){
        return tbHouseInfoService.assign(assignVo);
    }

    /** @Author 曹承坤
     * @Description //TODO 经纪人列表
     * @Date 09:02 23/11/11
     * @Param
     * @param tbHouseInfoVo
     * @return
     * @return com.bw.result.ResultVo
     **/
    @PostMapping("/brokerList")
    @ApiOperation("经纪人列表")
    public ResultVo brokerList(@RequestBody TbHouseInfoVo tbHouseInfoVo){
        return tbHouseInfoService.brokerList(tbHouseInfoVo);
    }

    /** @Author 曹承坤
     * @Description //TODO 房源详情
     * @Date 09:02 23/11/11
     * @Param
     * @param idVo
     * @return
     * @return com.bw.result.ResultVo
     **/
    @PostMapping("/houseContent")
    @ApiOperation("房源详情")
    @Cacheable(cacheNames = "com.bw.vo.TbHouseInfoVo",key = "#idVo.id")
    public ResultVo houseContent(@RequestBody IdVo idVo){
        return tbHouseInfoService.houseContent(idVo);
    }

    /** @Author 曹承坤
     * @Description //TODO 管理员登录
     * @Date 11:43 23/11/13
     * @Param
     * @param loginVo
     * @return
     * @return com.bw.result.ResultVo
     **/
    @PostMapping("/AdminLogin")
    @ApiOperation("管理员登录")
    public ResultVo login(@RequestBody LoginVo loginVo){
        return tbHouseInfoService.login(loginVo);
    }
    /** @Author 曹承坤
     * @Description //TODO 通过phone获取管理员
     * @Date 11:43 23/11/13
     * @param phone
     * @return com.bw.result.ResultVo
     **/
    @PostMapping("/getAdminByPhone")
    @ApiOperation("通过手机号获取管理员")
    public Boolean getAdminByPhone(@RequestParam("phone") String phone){
        return tbHouseInfoService.getAdminByPhone(phone);
    }


}
